﻿using Microsoft.SharePoint;

namespace SharePoint.Orm.Helpers {
	/// <summary>
	/// Collection of methods for working with <see cref="SPFieldUserValue"/>s.
	/// </summary>
	public class SPFieldUserValueHelper {
		/// <summary>
		/// Gets the LoginName value or null. If "val" is null, returns null. If "val.User" is null, returns
		/// null. Otherwise returns "val.User.LoginName".
		/// </summary>
		/// <param name="val">The value to get the LoginName from</param>
		/// <returns>The LoginName.</returns>
		public static string GetLoginNameOrDefault(SPFieldUserValue val) {
			if (val == null) {
				return "";
			}
			if (val.User == null) {
				return "";
			}
			return val.User.LoginName;
		}
	}
}
